public class LC4D {
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int n=nums1.length;
        int m=nums2.length;
        int i=0,j=0;
        int count=0;
        int[] all=new int[n+m];
        while (i<n && j<m){
            if (nums1[i]<nums2[j]){
                all[count++]=nums1[i++];
            }
            else{
                all[count++]=nums2[j++];
            }
        }
        while (i<n){
            all[count++]=nums1[i++];
        }
        while (j<m){
            all[count++]=nums2[j++];
        }
        int left=0;
        int right=n+m-1;
        while (left<right-1){
            left++;
            right--;
        }
        if (left==right)
            return all[left];
        if (left==right-1)
            return (all[left]+all[right])/2.0;
        return 0;
    }
}
